package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.db.Announcement;
import com.tanhua.dubbo.mapper.AnnouncementMapper;
import com.tanhua.vo.PageResult;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @version 1.0
 * @author： xtr
 * @date： 2021-03-10 18:54
 */
@Service
public class AnnouncementsApiImpl implements AnnouncementsApi {

    @Autowired
    private AnnouncementMapper announcementMapper;
    /**
     * 查询所有公告
     *
     * @param page
     * @param pagesize
     * @return
     */
    @Override
    public PageResult<Announcement> getAnnouncement(long page, long pagesize) {
        Page<Announcement> pages = new Page<>(page,pagesize);
        IPage<Announcement> announcementIPage = announcementMapper.selectPage(pages, new QueryWrapper<>());
        PageResult<Announcement> pageResult = new PageResult<>(announcementIPage.getTotal(), announcementIPage.getSize(), announcementIPage.getPages(), announcementIPage.getCurrent(), announcementIPage.getRecords());
        return pageResult;
    }
}
